package models

//出口滞港花费清单

type Spend2 struct {
	Inno2   string `gorm:"column:inno2"`
	Spend2  string `gorm:"column:spend2"`
	Object1 string `gorm:"column:object1"`
}

func GetAllSpend2(Spend2Param map[string]interface{}) (error, []Spend2, int64) {
	var spend2Data []Spend2
	page := Spend2Param["page"].(int)
	pageSize := Spend2Param["limit"].(int)
	searchText := Spend2Param["searchText"].(string)
	var total int64
	err := db.Table("spend2").Where("inno2 like ?", "%"+searchText+"%").Order("inno2 ASC").Count(&total).Find(&spend2Data).Offset((page - 1) * pageSize).Limit(pageSize).Error
	return err, spend2Data, total
}
func AddSpend2(spend2data Spend2) (error, Spend2) {
	err := db.Table("spend2").Select("inno2", "spedn2", "object1").Create(&spend2data).Error
	return err, spend2data
}

func UpdateSpend2(inno2 string, spend2data Spend2) (error, Spend2) {
	err := db.Table("spend2").Where("inno2 = ?", spend2data.Inno2).Updates(&spend2data).Error
	return err, spend2data
}

func DeleteSpend2(inno2 string) (error, Spend2) {
	var spend2data Spend2
	spend2data.Inno2 = inno2
	err := db.Table("spend2").Where("inno2 = ?", inno2).Find(&spend2data).Delete(Spend2{}).Error
	return err, spend2data
}
